package stack.mine;

import java.util.ArrayList;

/**
 * @BelongsProject: leetcode
 * @BelongsPackage: stack.mine
 * @Author: Administrator
 * @CreateTime: 2018-12-09 16:30
 * @Description: 155. 最小栈
 */
public class MinStack {
    private ArrayList<Integer> arrayList ;
    private int min;

    public MinStack() {
        arrayList =new ArrayList<>();
    }

    public void push(int x) {
        arrayList.add(x);
    }

    public void pop() {
        arrayList.remove(arrayList.size()-1);
    }

    public int top() {
        return arrayList.get(arrayList.size()-1);
    }

    public int getMin() {
        if (arrayList.isEmpty())
            return -1;
        int min=arrayList.get(0);
        if (arrayList.size()==1)
            return min;

        for (int i = 0; i <arrayList.size(); i++) {
            if (min > arrayList.get(i)){
                min=arrayList.get(i);
            }
        }
        return  min;
    }
}
